package com.ag.hmk.action;

import javax.annotation.Resource;

import com.ag.admin.service.impl.UserServiceImpl;
import com.ag.bean.TbExpert;
import com.ag.hmk.service.impl.ExpertServImpl;
import com.opensymphony.xwork2.ActionSupport;

/**
 *@author 黄木看
 *删除专家记录action 
 */
public class DelExpertAction extends ActionSupport {

	private static final long serialVersionUID = -8096799904606374885L;
	
	private ExpertServImpl expertServImpl;
	@Resource(name = "userServiceImpl")
	private UserServiceImpl userService;
	
	private String expertID; //专家ID
	private String ajaxRST;  //返回值，标志是否删除成功
	
	/*
	 * 删除专家记录方法(先删除专家，后删除用户)
	 */
	public String delExpert()throws Exception{
		try {
			this.setAjaxRST("0");
			TbExpert expert = expertServImpl.findByExpertID(expertID);
			if(expert!=null){
				expertServImpl.delExpert(expert);
				if (userService.deleteExpertUser(expertID)) {
					this.setAjaxRST("1");
					System.out.println("========del expert and user ok============");
				} else{
				this.setAjaxRST("0");
				System.out.println("========del  user error============");
				}
			}else{
				this.setAjaxRST("0");
				System.out.println("========del expert and user error============");
			}
		} catch (Exception e) {
			e.printStackTrace();
			this.setAjaxRST("0");
		}
		
		return "delExpertOK";
	}

	public void setExpertServImpl(ExpertServImpl expertServImpl) {
		this.expertServImpl = expertServImpl;
	}

	public void setExpertID(String expertID) {
		this.expertID = expertID;
	}

	public String getAjaxRST() {
		return ajaxRST;
	}

	public void setAjaxRST(String ajaxRST) {
		this.ajaxRST = ajaxRST;
	}

}
